package com.baizhi.service.impl;

import com.baizhi.dao.HeroDao;
import com.baizhi.entity.Hero;
import com.baizhi.service.HeroService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class HeroServiceImpl implements HeroService {
//    @Autowired
    @Resource
    private HeroDao heroDao;
    @Override
    public void insert(Hero hero) {
        heroDao.insert(hero);
    }

    @Override
    public void delete(Integer id) {
        heroDao.delete(id);
    }

    @Override
    @Transactional(readOnly = true)
    public Hero selectById(Integer id) {
        Hero hero = heroDao.selectById(id);
        return hero;
    }

    @Override
    public void update(Hero hero) {
        heroDao.update(hero);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Hero> select(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Hero> heroes = heroDao.selectAll();
        PageInfo<Hero> pageInfo = new PageInfo<>(heroes);
        return pageInfo;
    }
}
